home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / Date / DateCalc.pm next >
Encoding:
Perl POD Document  |  1999-12-28  |  25.2 KB  |  794 lines

  1.  
  2.  
  3. package Date::DateCalc;
  4.  
  5. require Exporter;
  6. require DynaLoader;
  7.  
  8. @ISA = qw(Exporter DynaLoader);
  9.  
  10. @EXPORT = qw();
  11.  
  12. @EXPORT_OK = qw( leap check_date compress uncompress check_compressed
  13. compressed_to_short calc_days day_of_week dates_difference calc_new_date
  14. date_time_difference calc_new_date_time date_to_short date_to_string
  15. week_number first_in_week weeks_in_year day_name_tab month_name_tab
  16. decode_day decode_month decode_date days_in_month );
  17.  
  18. %EXPORT_TAGS = (all => [@EXPORT_OK]);
  19.  
  20.  
  21. $VERSION = '3.2';
  22.  
  23. bootstrap Date::DateCalc $VERSION;
  24.  
  25. 1;
  26.  
  27. __END__
  28.  
  29. =head1 NAME
  30.  
  31. Date::DateCalc - Gregorian Calendar Date Calculations
  32.  
  33. in compliance with ISO/R 2015-1971 and DIN 1355 standards
  34.  
  35. =head1 SYNOPSIS
  36.  
  37. C<use Date::DateCalc;>
  38.  
  39. (in which case you must fully qualify every function with the name
  40. of this module, for example C<$flag = Date::DateCalc::leap($year)>)
  41.  
  42. or
  43.  
  44. C<use Date::DateCalc>
  45. C<qw( leap check_date compress uncompress check_compressed>
  46. C<compressed_to_short calc_days day_of_week dates_difference>
  47. C<calc_new_date date_time_difference calc_new_date_time>
  48. C<date_to_short date_to_string week_number first_in_week>
  49. C<weeks_in_year day_name_tab month_name_tab decode_day>
  50. C<decode_month decode_date days_in_month );>
  51.  
  52. (or only portions thereof, whatever you need)
  53.  
  54. or
  55.  
  56. C<use DateCalc qw(:all);>
  57.  
  58. (which imports everything).
  59.  
  60. =head1 DESCRIPTION
  61.  
  62. =head2 ===========
  63.  
  64. =head2 Convention:
  65.  
  66. =head2 ===========
  67.  
  68. In the following, "$year" stands for a "complete" year number
  69. (like "1995", for instance), whereas "$yy" may be an abbreviated
  70. year number (like "95") OR a complete year number.
  71.  
  72. Year numbers must be positive integers (greater than zero).
  73.  
  74. "$mm" stands for the number of a month (from 1 to 12), and "$dd"
  75. is the number of a day in a month (from 1 to 28,29,30 or 31,
  76. depending on the month and the year).
  77.  
  78. Hint: The functions that support abbreviated year numbers are
  79. the functions whose names contain the word "compress" and the
  80. function "decode_date()".
  81.  
  82. =head2   ====================
  83.  
  84. =head2 C<$flag = leap($year);>
  85.  
  86. =head2   ====================
  87.  
  88. This function returns a boolean value which is "true" (1) if the
  89. year "$year" is a leap year, and "false" (0) otherwise.
  90.  
  91. No check is made if the year "$year" is in the valid range.
  92.  
  93. For years less than 1, the result is probably meaningless (it IS
  94. almost meaningless, anyway, for years before 1582).
  95.  
  96. =head2   ==================================
  97.  
  98. =head2 C<$flag = check_date($year,$mm,$dd);>
  99.  
  100. =head2   ==================================
  101.  
  102. This function returns a boolean value which is "true" (1) if the
  103. three numbers "$year", "$mm" and "$dd" represent a valid date,
  104. and "false" (0) otherwise.
  105.  
  106. When determining validity, leap years are taken into account,
  107. i.e., the 29th of february is rejected in non-leap years.
  108.  
  109. Year numbers must be greater than zero (negative values will be
  110. interpreted as large positive numbers due to their internal 2's
  111. complement binary representation). A year number of zero is invalid.
  112.  
  113. =head2   ==============================
  114.  
  115. =head2 C<$date = compress($yy,$mm,$dd);>
  116.  
  117. =head2   ==============================
  118.  
  119. This function encodes a date in 16 bits. The encoding scheme is
  120. as follows:
  121.  
  122.     Bit-No.:       FEDCBA9 8765 43210
  123.     Contents:      yyyyyyy mmmm ddddd
  124.  
  125. All bits equal to zero is equivalent to "<no date>".
  126.  
  127. Through this encoding scheme, it is possible to COMPARE ENCODED
  128. DATES for equality and ORDER (less than/greater than) WITHOUT
  129. any previous DECODING!!
  130.  
  131. Note however that contiguous dates DO NOT NECESSARILY have
  132. contiguous compressed representations!
  133.  
  134. I.e., incrementing the compressed representation of a date may or
  135. MAY NOT yield a valid new date!
  136.  
  137. Note also that this function can only handle dates within one century.
  138.  
  139. This century can be biased at will by choosing a base century and year
  140. (also called an "epoch"). In this module, the base century is set to
  141. 1900 and the base year to 70 (standard on UNIX systems).
  142.  
  143. This allows the function to handle dates from 1970 up to 2069.
  144.  
  145. If the year "$yy" is equal to, say, 95, it is automatically
  146. assumed that 1995 is meant. However, if you specify a year
  147. number which is SMALLER than 70, like 64, for instance, it
  148. is assumed that you meant 2064.
  149.  
  150. You are not confined to abbreviated year numbers (smaller than
  151. 100), however. The function also accepts complete year numbers,
  152. provided that they are in the supported range (that is, from
  153. 1970 to 2069).
  154.  
  155. If no valid date is specified, zero is returned.
  156.  
  157. =head2   ======================================
  158.  
  159. =head2 C<($cc,$yy,$mm,$dd) = uncompress($date);>
  160.  
  161. =head2   ======================================
  162.  
  163. This function decodes dates that were encoded by "compress()".
  164. It returns the century, year, month and day of the date encoded
  165. in "$date" in the variables "$cc", "$yy", "$mm" and "$dd",
  166. respectively.
  167.  
  168. The expression "$cc + $yy" yields the complete year number (for
  169. example, 1900 + 95 = 1995).
  170.  
  171. If "$date" is zero or does not contain the compressed representation
  172. of a valid date, an empty list is returned.
  173.  
  174. =head2   ================================
  175.  
  176. =head2 C<$flag = check_compressed($date);>
  177.  
  178. =head2   ================================
  179.  
  180. This function returns a boolean value which is "true" (1) if
  181. "$date" contains a valid encoded date, and "false" (0) otherwise.
  182.  
  183. When determining validity, leap years are taken into account,
  184. i.e., the 29th of february is rejected in non-leap years.
  185.  
  186. =head2   ======================================
  187.  
  188. =head2 C<$datestr = compressed_to_short($date);>
  189.  
  190. =head2   ======================================
  191.  
  192. This function converts the encoded date in "$date" to a string
  193. of the format "dd-mmm-yy", which is returned.
  194.  
  195. ("mmm" is the 3-letter abbreviation (in English) of the month's name.)
  196.  
  197. If the date in "$date" is invalid, the string "<no date>" is
  198. returned.
  199.  
  200. Note that the string which is returned by this function is
  201. always exactly 9 characters long.
  202.  
  203. =head2   =================================
  204.  
  205. =head2 C<$days = calc_days($year,$mm,$dd);>
  206.  
  207. =head2   =================================
  208.  
  209. This function returns the (theoretical) number of days between
  210. the first of january of the year one and the given date *plus one*.
  211.  
  212. I.e., the value returned for the first of january of the year one
  213. is 1, the value returned for the second of january of the year one
  214. is 2, and so on.
  215.  
  216. This is because there is no year zero; the christian calendar starts
  217. with the year one. Consequently, there is also no day zero; the calendar
  218. starts with the first day, i.e., day one.
  219.  
  220. The function doesn't take into account the change from the Julian to
  221. the Gregorian calendar (used today) in 1582 (or later, for some countries),
  222. it simply extrapolates the gregorian calendar backwards.
  223.  
  224. This function is used internally to calculate the difference in days
  225. between two dates and to calculate the day of week.
  226.  
  227. Use this function to compare dates for "less than" and "greater than",
  228. or to compare dates for equality more easily.
  229.  
  230. Zero is returned if no valid date is specified.
  231.  
  232. (This is another reason why "C<calc_days(1,1,1)>" is equal to one and
  233. not to zero!)
  234.  
  235. =head2   ======================================
  236.  
  237. =head2 C<$weekday = day_of_week($year,$mm,$dd);>
  238.  
  239. =head2   ======================================
  240.  
  241. This function calculates the day of week for the given date
  242. (which must be a valid date).
  243.  
  244. The return values have the following meaning:
  245.  
  246.         0       =       Error
  247.         1       =       Monday
  248.         2       =       Tuesday
  249.         3       =       Wednesday
  250.         4       =       Thursday
  251.         5       =       Friday
  252.         6       =       Saturday
  253.         7       =       Sunday
  254.  
  255. The value zero is returned if the date is not valid.
  256.  
  257. =head2   ============================================================
  258.  
  259. =head2 C<$days = dates_difference($year1,$mm1,$dd1,$year2,$mm2,$dd2);>
  260.  
  261. =head2   ============================================================
  262.  
  263. This function calculates the difference in days between the two
  264. given dates.
  265.  
  266. The function calculates the difference "date 2" - "date 1", i.e.,
  267. you normally specify the two dates in chronological order.
  268.  
  269. If date 1 is later than date 2, the result will be negative,
  270. which allows you to use this function to compare dates.
  271.  
  272. If one of the two dates is invalid, the result will degrade
  273. to the value of the function "calc_days()" for the other date
  274. (possibly negative). If both dates are invalid, the result is
  275. zero.
  276.  
  277. It is the user's responsibility to make sure that both dates
  278. are valid (use "check_date()" for this)!
  279.  
  280. =head2   =======================================================
  281.  
  282. =head2 C<($year,$mm,$dd) = calc_new_date($year,$mm,$dd,$offset);>
  283.  
  284. =head2   =======================================================
  285.  
  286. Starting from the given date, a new date can be calculated with
  287. this function which is "$offset" days away from the original
  288. date. "$offset" may be positive (for a date later than the
  289. original date) or negative (for a date earlier than the given date).
  290.  
  291. If the given date is invalid or the new date cannot be calculated
  292. (for instance, if the new date would be before the year one),
  293. an empty list is returned.
  294.  
  295. To calculate a new date with a year, month and day offset, see the
  296. function "year_month_day_offset()" in the "Date::DateCalcLib" module.
  297.  
  298. =head2   ===========================================
  299.  
  300. =head2 C<($days,$hh,$mm,$ss) = date_time_difference( $year1,$month1,$day1,$hh1,$mm1,$ss1, $year2,$month2,$day2,$hh2,$mm2,$ss2 );>
  301.  
  302. =head2   ===========================================
  303.  
  304. This function calculates the difference in days, hours, minutes
  305. and seconds between the two given dates.
  306.  
  307. The function calculates the difference "date 2" - "date 1", i.e.,
  308. you normally specify the two dates in chronological order.
  309.  
  310. If date 1 is later than date 2, the result will be negative
  311. in every of the four return values, which allows you to use
  312. this function to compare dates and to feed its output into
  313. the function explained next in this text, "calc_new_date_time()".
  314.  
  315. If one (or both) of the two date/time pairs is invalid, an empty
  316. list is returned.
  317.  
  318. A date/time pair is invalid either when the date is invalid or
  319. when the values for hour, minute and second are outside the range
  320. of 0..23, 0..59 and 0..59, respectively.
  321.  
  322. =head2   =====================================================
  323.  
  324. =head2 C<($year,$month,$day,$hh,$mm,$ss) = calc_new_date_time( $year,$month,$day,$hh,$mm,$ss, $days_offset,$hh_offset,$mm_offset,$ss_offset );>
  325.  
  326. =head2   =====================================================
  327.  
  328. Starting from the given date and time, a new date and time can
  329. be calculated with this function.
  330.  
  331. The new date will be "$days_offset" days and "$hh_offset" hours,
  332. "$mm_offset" minutes and "$ss_offset" seconds away from the
  333. original date. The values of these four offsets may be positive or
  334. negative, independently from each other. This means that you can
  335. add, for instance, 9 hours and subtract 5 minutes at the same time.
  336.  
  337. If the new date and time cannot be calculated (for instance, if
  338. the given date is invalid or the new date would be before the year
  339. one, or the values for hour, minute and second are outside the
  340. range of 0..23, 0..59 and 0..59, respectively), an empty list is
  341. returned.
  342.  
  343. =head2   ========================================
  344.  
  345. =head2 C<$datestr = date_to_short($year,$mm,$dd);>
  346.  
  347. =head2   ========================================
  348.  
  349. This function converts the given date to a string of the format
  350. "www dd-mmm-yyyy", which is returned.
  351.  
  352. "www" is a (3-letter) abbreviation of the day of week, and "mmm"
  353. is a (3-letter) abbreviation of the month (both in English).
  354.  
  355. If the given date is invalid, the string "<no date>" is returned.
  356.  
  357. =head2   =========================================
  358.  
  359. =head2 C<$datestr = date_to_string($year,$mm,$dd);>
  360.  
  361. =head2   =========================================
  362.  
  363. This function converts the given date to a string of the format
  364. "wwwwwwwww, dd mmmmmmmmm yyyy", which is returned.
  365.  
  366. "wwwwwwwww" is the day of week and "mmmmmmmmm" the name of the
  367. month (both in English).
  368.  
  369. If the given date is invalid, the string "<no date>" is returned.
  370.  
  371. =head2   ===========================================
  372.  
  373. =head2 C<($week,$year) = week_number($year,$mm,$dd);>
  374.  
  375. =head2   ===========================================
  376.  
  377. This function calculates the number of the week in which the
  378. given date lies.
  379.  
  380. This can occasionally be the last week of the previous year
  381. or the first week of the next year.
  382.  
  383. If the given date is invalid, an empty list is returned.
  384.  
  385. =head2   =============================================
  386.  
  387. =head2 C<($year,$mm,$dd) = first_in_week($week,$year);>
  388.  
  389. =head2   =============================================
  390.  
  391. This function calculates the date of the first day (the Monday)
  392. of the given week in the given year.
  393.  
  394. The return value "$year" is adjusted accordingly if the first
  395. day of the given week lies in the previous year.
  396.  
  397. If the week number is invalid (less than one or greater than the
  398. number of weeks of the given year, as returned by the function
  399. "weeks_in_year()"), or if the year is invalid or the date cannot
  400. be calculated (for example, if the calculated date would be before
  401. the year one), an empty list is returned.
  402.  
  403. With help of the expression
  404.  
  405.     ($year,$mm,$dd) = first_in_week(week_number($year,$mm,$dd));
  406.  
  407. it is possible to easily calculate the date of the Monday belonging
  408. to the week in which the given date lies.
  409.  
  410. (However, a fatal Perl error will occur if the given date is invalid!)
  411.  
  412. Alternatively, the expression
  413.  
  414.     ($year,$mm,$dd) =
  415.     calc_new_date($year,$mm,$dd,-day_of_week($year,$mm,$dd)+1);
  416.  
  417. can be used to achieve the same effect.
  418.  
  419. (An empty list is returned if the given date is invalid.)
  420.  
  421. =head2   ==============================
  422.  
  423. =head2 C<$weeks = weeks_in_year($year);>
  424.  
  425. =head2   ==============================
  426.  
  427. This function returns the number of weeks of the given year
  428. (52 or 53 weeks).
  429.  
  430. No check is made if the year "$year" is in the valid range.
  431.  
  432. For years less than 1, the result is probably meaningless.
  433.  
  434. =head2   ===================================
  435.  
  436. =head2 C<$day_name = day_name_tab($weekday);>
  437.  
  438. =head2   ===================================
  439.  
  440. This function accesses the internal table of the days of week.
  441.  
  442. It returns the corresponding string for each numeric value of a
  443. day of week (as returned by the function "day_of_week()").
  444.  
  445. The value of "$weekday" is taken modulo 8 (!) internally to prevent
  446. out-of-range access to the internal array.
  447.  
  448. The strings which are returned are the following:
  449.  
  450.         0       =>      Error
  451.         1       =>      Monday
  452.         2       =>      Tuesday
  453.         3       =>      Wednesday
  454.         4       =>      Thursday
  455.         5       =>      Friday
  456.         6       =>      Saturday
  457.         7       =>      Sunday
  458.  
  459. =head2   =====================================
  460.  
  461. =head2 C<$month_name = month_name_tab($month);>
  462.  
  463. =head2   =====================================
  464.  
  465. This function accesses the internal table of the months' names.
  466.  
  467. It returns the corresponding string for each numeric value of a
  468. month.
  469.  
  470. The value of "$month" is taken modulo 13 (!) internally to prevent
  471. out-of-range access to the internal array.
  472.  
  473. The strings which are returned are the following:
  474.  
  475.          0       =>      Error
  476.          1       =>      January
  477.          2       =>      February
  478.          3       =>      March
  479.          4       =>      April
  480.          5       =>      May
  481.          6       =>      June
  482.          7       =>      July
  483.          8       =>      August
  484.          9       =>      September
  485.         10       =>      October
  486.         11       =>      November
  487.         12       =>      December
  488.  
  489. =head2   ===============================
  490.  
  491. =head2 C<$weekday = decode_day($buffer);>
  492.  
  493. =head2   ===============================
  494.  
  495. This function provides the inverse of the function "day_name_tab()".
  496.  
  497. Whereas "day_name_tab()" takes a number as its argument and returns
  498. a string, "decode_day()" takes a string (of any length) and tries
  499. to match it with the table of the names of days ("Monday", "Tuesday",
  500. and so on) and returns the corresponding number (1..7).
  501.  
  502. Only the first 3 characters are checked (in case-insensitive
  503. manner) for a unique match. If it uniquely identifies the day,
  504. you may also provide only one or two characters:
  505.  
  506.     Name of the day:     Uniquely identified by:     Value returned:
  507.  
  508.            Monday        M, Mo, Mon, ... Monday            1
  509.            Tuesday          Tu, Tue, ... Tuesday           2
  510.            Wednesday     W, We, Wed, ... Wednesday         3
  511.            Thursday         Th, Thu, ... Thursday          4
  512.            Friday        F, Fr, Fri, ... Friday            5
  513.            Saturday         Sa, Sat, ... Saturday          6
  514.            Sunday           Su, Sun, ... Sunday            7
  515.  
  516. If there is no match, zero is returned.
  517.  
  518. This function is roughly equivalent to an associative array:
  519.  
  520.     %day_tab = ( 'Mon' => 1, 'Tue' => 2, 'Wed' => 3, 'Thu' => 4,
  521.                  'Fri' => 5, 'Sat' => 6, 'Sun' => 7);
  522.     $weekday = $day_tab{$buffer};
  523.  
  524. except for the capability of recognizing abbreviations and
  525. to be case-independent.
  526.  
  527. =head2   ===============================
  528.  
  529. =head2 C<$month = decode_month($buffer);>
  530.  
  531. =head2   ===============================
  532.  
  533. This function provides the inverse of the function "month_name_tab()".
  534.  
  535. Whereas "month_name_tab" takes a number as its argument and returns
  536. a string, "decode_month" takes a string (of any length) and tries to
  537. match it with the table of the names of months ("January", "February",
  538. and so on) and returns the corresponding number (1..12).
  539.  
  540. Only the first 3 characters are checked (in case-insensitive
  541. manner) for a unique match. If it uniquely identifies the month,
  542. you may also provide only one or two characters:
  543.  
  544.     Name of the month:     Uniquely identified by:     Value returned:
  545.  
  546.              January          Ja, Jan, ... January           1
  547.              February      F, Fe, Feb, ... February          2
  548.              March                Mar, ... March             3
  549.              April            Ap, Apr, ... April             4
  550.              May                  May, ... May               5
  551.              June                 Jun, ... June              6
  552.              July                 Jul, ... July              7
  553.              August           Au, Aug, ... August            8
  554.              September     S, Se, Sep, ... September         9
  555.              October       O, Oc, Oct, ... October          10
  556.              November      N, No, Nov, ... November         11
  557.              December      D, De, Dec, ... December         12
  558.  
  559. If there is no match, zero is returned.
  560.  
  561. This function is roughly equivalent to an associative array:
  562.  
  563.     %month_tab = ( 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4,
  564.                    'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8,
  565.                    'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12);
  566.     $month = $month_tab{$buffer};
  567.  
  568. except for the capability of recognizing abbreviations and
  569. to be case-independent.
  570.  
  571. =head2   =======================================
  572.  
  573. =head2 C<($year,$mm,$dd) = decode_date($buffer);>
  574.  
  575. =head2   =======================================
  576.  
  577. Using this function, it is possible to parse dates in almost
  578. any format, provided the date is given as "day - month - year".
  579.  
  580. (To decode dates in U.S. american format, i.e., dates given
  581. as "month - day - year", see the function "decode_date_us()"
  582. in the "Date::DateCalcLib" module.)
  583.  
  584. The day and the year must be given as numbers, the month may be
  585. specified either by a number or an abbreviation (up to 3 characters
  586. long) of the month's name in English (case is ignored).
  587.  
  588. If they uniquely identify the month, one or two letters are
  589. sufficient (e.g. "s" for september or "ja" for january).
  590.  
  591. The year may be abbreviated as well, for instance "95" instead
  592. of "1995". (Year numbers below 100 are incremented by 1900.)
  593.  
  594. Any number of non-digits (i.e., all characters NOT in [0-9]) may
  595. precede the number of the day and follow the number of the year.
  596.  
  597. Any number of non-alphanumeric characters (i.e., all characters NOT
  598. in [A-Za-z0-9]) may separate the number of the day and the month and
  599. the month and the number of the year.
  600.  
  601. If after removing the preceding and trailing non-digit characters
  602. the string consists only of digits, it is automatically mapped to
  603. the day, month and year depending on its length, as intuitively as
  604. possible, as follows:
  605.  
  606.         Length:        Mapping:
  607.           3              dmy
  608.           4              dmyy
  609.           5              dmmyy
  610.           6              ddmmyy
  611.           7              dmmyyyy
  612.           8              ddmmyyyy
  613.  
  614. Example:
  615.  
  616. All the following strings will be recognized as "January 3rd 1964":
  617.  
  618.               3.1.64
  619.               3 1 64
  620.              03.01.64
  621.              03/01/64
  622.             3. Jan 1964
  623.             3. Jan '64
  624.              03-Jan-64
  625.              3.Jan1964
  626.               3Jan64
  627.                3ja64
  628.                3164
  629.  
  630. If the function is unable to extract a valid date from its input,
  631. it returns an empty list.
  632.  
  633. =head2   =================================
  634.  
  635. =head2 C<$days = days_in_month($year,$mm);>
  636.  
  637. =head2   =================================
  638.  
  639. This function accesses the internal table of the months' lengths
  640. and returns the length in days of the given month "$mm" in the
  641. given year "$year".
  642.  
  643. It is necessary to specify the year "$year" since the length of
  644. the month february is 29 instead of 28 in leap years.
  645.  
  646. This function is useful, for example, to calculate the last day
  647. of a month or the last working-day (payday!) of a month.
  648.  
  649. Last working-day of the month (legal holidays not taken into
  650. account):
  651.  
  652.     $dd = days_in_month($year,$mm);
  653.     $dw = day_of_week($year,$mm,$dd) - 1;
  654.     if ($dw > 4)
  655.     {
  656.         ($year,$mm,$dd) = calc_new_date($year,$mm,$dd,4-$dw);
  657.     }
  658.  
  659. Last working-day of the month (legal holidays taken into account):
  660.  
  661. (assuming that the array C<$holiday[$year][$mm][$dd] = 1;> contains
  662. all legal holidays)
  663.  
  664.     $dd = days_in_month($year,$mm);
  665.     while (1)
  666.     {
  667.         while ($holiday[$year][$mm][$dd])
  668.         {
  669.             ($year,$mm,$dd) = calc_new_date($year,$mm,$dd,-1);
  670.         }
  671.         $dw = day_of_week($year,$mm,$dd) - 1;
  672.         if ($dw > 4)
  673.         {
  674.             ($year,$mm,$dd) = calc_new_date($year,$mm,$dd,4-$dw);
  675.         }
  676.         else { last; }
  677.     }
  678.  
  679. The value of "$mm" is taken modulo 13 (!) internally to prevent
  680. out-of-range access to the internal array.
  681.  
  682. The values the internal array contains are the following:
  683.  
  684.     normal             leap
  685.      month             year              year
  686.  
  687.        0                 0                 0
  688.        1                31                31
  689.        2                28                29
  690.        3                31                31
  691.        4                30                30
  692.        5                31                31
  693.        6                30                30
  694.        7                31                31
  695.        8                31                31
  696.        9                30                30
  697.       10                31                31
  698.       11                30                30
  699.       12                31                31
  700.  
  701. =head2   =====================================
  702.  
  703. =head2 C<$version = Date::DateCalc::Version();>
  704.  
  705. =head2   =====================================
  706.  
  707. This function returns a string with the (numeric) version
  708. number of the "DateCalc" extension package.
  709.  
  710. Since this function is not exported, you always have to
  711. qualify it explicitly (i.e., "C<Date::DateCalc::Version()>").
  712.  
  713. This is to avoid possible conflicts with version functions
  714. from other packages.
  715.  
  716. =head1 EXAMPLE
  717.  
  718.  
  719.     use strict;
  720.     no strict "vars";
  721.  
  722.     use Date::DateCalc qw(decode_date date_to_short dates_difference);
  723.  
  724.     print "\n";
  725.  
  726.     $ok = 0;
  727.     while (! $ok)
  728.     {
  729.         print "Please enter the date of your birthday (day-month-year): ";
  730.         $date = <STDIN>;
  731.         print "\n";
  732.         if (($yy1,$mm1,$dd1) = decode_date($date))
  733.         {
  734.             $datestr = date_to_short($yy1,$mm1,$dd1);
  735.             print "Your date is: $datestr\n";
  736.             print "\n";
  737.             print "Is that correct? (Yes/No) ";
  738.             $response = <STDIN>;
  739.             print "\n";
  740.             $ok = ($response =~ /^Y/i);
  741.         }
  742.     }
  743.     print "Your birthday is: $datestr\n";
  744.     print "\n";
  745.  
  746.     $ok = 0;
  747.     while (! $ok)
  748.     {
  749.         print "Please enter today's date (day-month-year): ";
  750.         $date = <STDIN>;
  751.         print "\n";
  752.         if (($yy2,$mm2,$dd2) = decode_date($date))
  753.         {
  754.             $datestr = date_to_short($yy2,$mm2,$dd2);
  755.             print "Your date is: $datestr\n";
  756.             print "\n";
  757.             print "Is that correct? (Yes/No) ";
  758.             $response = <STDIN>;
  759.             print "\n";
  760.             $ok = ($response =~ /^Y/i);
  761.         }
  762.     }
  763.     print "Today's date is: $datestr\n";
  764.     print "\n";
  765.  
  766.     $days = dates_difference($yy1,$mm1,$dd1,$yy2,$mm2,$dd2);
  767.     print "You are $days days old.\n";
  768.     print "\n";
  769.  
  770.     __END__
  771.  
  772. =head1 SEE ALSO
  773.  
  774. Date::DateCalcLib(3), perl(1), perlsub(1),
  775. perlmod(1), perlxs(1), perlxstut(1), perlguts(1).
  776.  
  777. =head1 VERSION
  778.  
  779. This man page documents "Date::DateCalc" version 3.2.
  780.  
  781. =head1 AUTHOR
  782.  
  783. Steffen Beyer <sb@sdm.de>.
  784.  
  785. =head1 COPYRIGHT
  786.  
  787. Copyright (c) 1995, 1996, 1997 by Steffen Beyer. All rights reserved.
  788.  
  789. =head1 LICENSE
  790.  
  791. This package is free software; you can redistribute it and/or modify
  792. it under the same terms as Perl itself.
  793.  
  794.